/*
 * Copyright 2010 Michael Nitsche
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package de.mnit.basis.daten.struktur.schluessel;

import de.mnit.basis.daten.struktur.gruppe.Gruppe2;
import de.mnit.basis.daten.struktur.menge.Menge;
import de.mnit.basis.daten.struktur.menge.S_Menge;
import de.mnit.basis.fehler.Fehler;


/**
 * @author Michael Nitsche
 */
public class SchluesselMenge<TA,TB> extends A_Schluessel_LM_Basis<TA,TB> implements S_SchluesselMenge<TA,TB> {

	public SchluesselMenge() {
		super();
		this.objekte = Menge.neu();
	}


	public static final <TA,TB> SchluesselMenge<TA,TB> neu() {
		return new SchluesselMenge<TA,TB>();
	}

	public static final <TA,TB> SchluesselMenge<TA,TB> neu(Class<TA> a, Class<TB> b) {
		return neu();
	}


	public S_Menge<TB> gObjekte() {
		return (S_Menge<TB>)this.objekte.kopie();
	}

	public TA gSchluessel(TB objekt) {
		Integer pos=((S_Menge<TB>)this.objekte).gPosition(objekt);
		if(pos==null)
			Fehler.liste.da_ElementFehlt(objekt);
		return this.gSchluessel().gib(pos);
	}

	public void sortiereSo(int[] so) {
		if(geschuetzt)
			throw Fehler.sicherheit.da_Geschuetzt();
		throw Fehler.sonstige.da_ToDo();
	}

	public S_SchluesselMenge<TA, TB> kopie() {
		SchluesselMenge<TA, TB> neu=SchluesselMenge.neu();
		for(Gruppe2<TA, TB> g : this)
			neu.plus(g.g1(), g.g2());
		return neu;
	}

}